package ljl.alg.jianzhioffer.round3.easy;

import commons.ListNode;

public class _24_reverseList {
    class iter {
        // null 1 2 3 4
        public ListNode reverseList(ListNode head) {
            ListNode pre = null, cur = head;
            while (cur != null) {
                ListNode n = cur.next;
                cur.next = pre;
                pre = cur;
                cur = n;
            }
            return pre;
        }
    }

    class recur {
        public ListNode reverseList(ListNode head) {
            if (head == null || head.next == null)
                return head;
            ListNode next = reverseList(head.next);
            head.next.next = head;
            head.next = null;
            return next;
        }
    }
}


